﻿using System;
using System.Data;
using System.Data.SqlClient;
using AccessControl.Common;

namespace AccessControl.DataAcess
{
    public class UpdateAccess
    {
        public static int RunUpdateCommand(string Command,out string errorMessage){
            errorMessage = null;
            int rowsAffected=0;
            using (var cnn = new SqlConnection(Util.ConnectionString))
            {
                var sqlcmd = new SqlCommand(Command,cnn);

                try
                {
                    cnn.Open();
                    rowsAffected = (int)sqlcmd.ExecuteScalar();

                }
                catch (Exception ex){
                    errorMessage = ex.Message;
                }finally{
                    cnn.Close();
                }
                return rowsAffected;
            }
        }
    }
}
